package org.eiahe.hr.attendance.converter;

import cn.idev.excel.converters.Converter;
import cn.idev.excel.enums.CellDataTypeEnum;
import cn.idev.excel.metadata.GlobalConfiguration;
import cn.idev.excel.metadata.data.ReadCellData;
import cn.idev.excel.metadata.data.WriteCellData;
import cn.idev.excel.metadata.property.ExcelContentProperty;

/**
 * 考勤异常状态转换器
 * 0->正常, 1->异常
 *
 * @author zhangnn
 */
public class AttendanceStatusConverter implements Converter<String> {

    @Override
    public Class<String> supportJavaTypeKey() {
        return String.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public String convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
            GlobalConfiguration globalConfiguration) {
        String cellValue = cellData.getStringValue();
        if ("正常".equals(cellValue)) {
            return "0";
        } else if ("异常".equals(cellValue)) {
            return "1";
        }
        return cellValue;
    }

    @Override
    public WriteCellData<String> convertToExcelData(String value, ExcelContentProperty contentProperty,
            GlobalConfiguration globalConfiguration) {
        if ("0".equals(value)) {
            return new WriteCellData<>("正常");
        } else if ("1".equals(value)) {
            return new WriteCellData<>("异常");
        }
        return new WriteCellData<>(value);
    }
}